#encoding: utf-8
class Forward < BizUnit
  has_many :bls

 #查询该场站所有提单中的航线汇总
  def routes
    bls = self.bls.select("distinct route").order("route")
    routes = Array.new
    bls.each { |bl| routes << bl.route }
    routes
  end

  #查询该场站所有提单中的航向汇总
  def courses
    bls = self.bls.select("distinct course").order("course")
    courses = Array.new
    bls.each { |bl| courses << bl.course }
    courses
  end

  #查询该场站所有提单中的航次汇总
  def voyages
    logger.debug "航次汇总"
    bls = self.bls.order("voyage").select("distinct voyage")
    courses = Array.new
    bls.each { |bl| courses << bl.voyage }
    courses
  end

  #查询该场站所有提单中的场站汇总
  def cies
    logger.debug "场站汇总"
    Cy.joins("right outer join bls on biz_units.id = bls.cy_id").where("bls.forward_id" => self.id).group("bls.cy_id").order("biz_units.code")
  end

  #查询该场站所有提单中的港口汇总
  def ports
    logger.debug "港口汇总"
    Port.joins("right outer join bls on biz_units.id = bls.port_id").where("bls.forward_id" => self.id).group("bls.port_id").order("biz_units.code")
  end

  #查询该场站所有提单中的船公司汇总
  def shipowners
    logger.debug "船公司汇总"
    Shipowner.joins("right outer join bls on biz_units.id = bls.shipowner_id").where("bls.forward_id" => self.id).group("bls.shipowner_id").order("biz_units.code")
  end

end